/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.icee.myth.server.pipelineFactory;

import com.icee.myth.common.encoder.Type4BytesLengthFieldProtobufEncoder;
import com.icee.myth.server.channelHandler.PlayerConnectHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutorGroup;


/**
 * Unity3d客户端，链接游戏服务器的初始化处理
 *
 * @author liuxianke
 */
public class PlayerClinetConnectGameServerPipelineInitializer extends ChannelInitializer<SocketChannel> {

    public PlayerClinetConnectGameServerPipelineInitializer() {}

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO));
        ch.pipeline().addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, 0, 0));
        ch.pipeline().addLast("customEncoder", new Type4BytesLengthFieldProtobufEncoder());

        final EventExecutorGroup e1 = new DefaultEventExecutorGroup(20);
        ch.pipeline().addLast(e1, new PlayerConnectHandler());
    }

}
